home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.awt;
-
- import java.applet.Applet;
- import java.awt.Canvas;
- import java.awt.Component;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.Toolkit;
- import java.io.BufferedInputStream;
- import java.io.ByteArrayInputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import symantec.itools.db.pro.ProjBinder;
- import symantec.itools.db.pro.ProjLink;
- import symantec.itools.db.pro.RelationView;
- import symjava.sql.SQLException;
-
- public class ImageViewer extends Canvas implements ProjLink {
- Image image;
- ProjBinder m_ProjBinder;
- int imageType = 1;
- private boolean m_DynamicUpdate = true;
- private InputStream m_ScreenInputStream;
- private InputStream m_BinderInputStream;
- private boolean m_displayWhileLoading = false;
- private boolean m_BinderDetermines = true;
- private int m_treatBlankAs;
- private boolean isLoaded = false;
- private byte[] coreImage;
-
- public ImageViewer() {
- }
-
- public ImageViewer(URL var1) {
- StreamImageSource.setBaseUrl(var1);
- }
-
- public static void setBaseUrl(URL var0) {
- StreamImageSource.setBaseUrl(var0);
- }
-
- public void addNotify() {
- super.addNotify();
- Object var1 = null;
- Object var2 = null;
-
- for(var3 = ((Component)this).getParent(); var3 != null && ((Component)var3).getParent() != null && !(var3 instanceof Applet); var3 = ((Component)var3).getParent()) {
- }
-
- if (var3 instanceof Applet) {
- Applet var4 = (Applet)var3;
- StreamImageSource.setBaseUrl(var4.getCodeBase());
- }
-
- }
-
- public int getImageType() {
- return this.imageType;
- }
-
- public boolean isLoaded() {
- return this.isLoaded;
- }
-
- public ByteArrayInputStream fetchImage(String var1) throws MalformedURLException {
- this.isLoaded = false;
- this.imageType = 1;
- URL var3 = new URL(var1);
- ByteArrayInputStream var2 = this.fetchImage(var3);
- if (this.m_ProjBinder != null) {
- this.notifyInputChanged(var2);
- }
-
- var2.reset();
- return var2;
- }
-
- public ByteArrayInputStream fetchHTTP(URL var1) throws MalformedURLException {
- try {
- InputStream var2 = var1.openStream();
- BufferedInputStream var3 = new BufferedInputStream(var2);
- ByteArrayOutputStream var4 = new ByteArrayOutputStream();
-
- int var5;
- while((var5 = var3.read()) != -1) {
- var4.write(var5);
- }
-
- this.coreImage = var4.toByteArray();
- } catch (Exception var6) {
- ((Throwable)var6).printStackTrace();
- throw new MalformedURLException(((Throwable)var6).getMessage());
- }
-
- this.isLoaded = true;
- return new ByteArrayInputStream(this.coreImage);
- }
-
- public ByteArrayInputStream fetchImage(URL var1) throws MalformedURLException {
- byte[] var5 = new byte[3];
- this.isLoaded = false;
- String var2 = var1.toExternalForm();
- ByteArrayInputStream var3 = this.fetchHTTP(var1);
- System.arraycopy(this.coreImage, 0, var5, 0, 3);
- String var4 = new String(var5, 0);
- if (var4.equals("GIF")) {
- this.imageType = 0;
- }
-
- this.buildImage(var3, this.imageType);
- ((Component)this).repaint();
- var3.reset();
- return var3;
- }
-
- public void setBinding(RelationView var1, String var2) {
- try {
- int var3 = var1.findProjByName(var2);
- var1.bindProj(var3, this);
- } catch (SQLException var4) {
- System.out.println(((Throwable)var4).getMessage());
- }
- }
-
- public void setDisplayOption(boolean var1) {
- if (var1) {
- this.m_displayWhileLoading = true;
- } else {
- this.m_displayWhileLoading = false;
- }
- }
-
- public void setImageType(int var1) {
- this.imageType = var1;
- }
-
- public void init(ProjBinder var1) {
- this.m_ProjBinder = var1;
- this.init();
- }
-
- public void init() {
- byte var2 = 1;
- this.image = null;
- this.m_BinderInputStream = null;
-
- try {
- if (this.m_ProjBinder.getRelationView().getCurrentRecordState() != 105 && this.m_ProjBinder != null && this.m_ProjBinder.isReadable() && !this.m_ProjBinder.isNull()) {
- byte var1 = this.m_ProjBinder.getByte();
- if (var1 == 71) {
- var2 = 0;
- }
-
- this.m_BinderInputStream = this.m_ProjBinder.getBinaryStream();
- }
- } catch (SQLException var5) {
- if (!((Throwable)var5).getMessage().startsWith("Can't convert data")) {
- System.out.println(((Throwable)var5).getMessage());
- }
- }
-
- this.m_ScreenInputStream = this.m_BinderInputStream;
- if (this.m_ScreenInputStream != null) {
- try {
- this.buildImage(this.m_ScreenInputStream, var2);
- } catch (MalformedURLException var4) {
- }
- }
-
- ((Component)this).repaint();
- }
-
- public void clearImage() {
- this.image = null;
- this.m_ScreenInputStream = null;
- ((Component)this).repaint();
- }
-
- private void buildImage(InputStream var1, int var2) throws MalformedURLException {
- try {
- Toolkit var3 = ((Component)this).getToolkit();
- StreamImageSource var4 = new StreamImageSource(var1, var2);
- this.image = var3.createImage(var4);
- if (!this.m_displayWhileLoading) {
- this.loadImage(this.image);
- }
- } catch (Exception var5) {
- ((Throwable)var5).printStackTrace();
- throw new MalformedURLException(((Throwable)var5).getMessage());
- }
- }
-
- private void loadImage(Image var1) {
- if (var1 != null) {
- try {
- MediaTracker var2 = new MediaTracker(this);
- var2.addImage(var1, 0);
- var2.waitForID(0);
- } catch (InterruptedException var3) {
- }
- }
- }
-
- public void notifyDataChange(ProjBinder var1) {
- try {
- if (var1 != null) {
- this.m_ProjBinder = var1;
- this.init(this.m_ProjBinder);
- }
- } catch (Exception var3) {
- ((Throwable)var3).printStackTrace();
- }
- }
-
- public boolean notifyInputChanged(InputStream var1) {
- if (this.m_ScreenInputStream == null || !this.m_ScreenInputStream.equals(var1)) {
- this.m_ScreenInputStream = var1;
- }
-
- try {
- if (this.m_BinderInputStream != this.m_ScreenInputStream || this.m_BinderInputStream != null && !this.m_BinderInputStream.equals(this.m_ScreenInputStream) && this.m_ProjBinder.getRelationView().getCurrentRecordState() != 105 && this.m_ProjBinder.getRelationView().getCurrentRecordState() != 103 && this.m_ProjBinder.getRelationView().getCurrentRecordState() != 104) {
- this.m_BinderInputStream = this.m_ScreenInputStream;
-
- try {
- if (this.m_BinderInputStream == null) {
- this.m_ProjBinder.setNull(-4);
- } else {
- this.m_ProjBinder.setBinaryStream(this.m_BinderInputStream, this.m_BinderInputStream.available());
- }
- } catch (IOException var3) {
- this.raiseException("IOException from TextField.notifyInputChange: " + ((Throwable)var3).getMessage());
- return false;
- }
- }
-
- return true;
- } catch (SQLException var4) {
- this.raiseException("SQLException from TextField.notifyInputChange: " + ((Throwable)var4).getMessage());
- return false;
- }
- }
-
- public boolean notifySetData(ProjBinder var1) throws SQLException {
- return this.notifyInputChanged(this.m_ScreenInputStream);
- }
-
- public void paint(Graphics var1) {
- try {
- if (this.image != null) {
- var1.drawImage(this.image, 0, 0, this);
- } else {
- var1.clearRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
- }
- } catch (Exception var3) {
- ((Throwable)var3).printStackTrace();
- }
- }
-
- public void setDynamicUpdate(boolean var1) {
- this.m_DynamicUpdate = var1;
- }
-
- public void setTreatBlankAs(String var1) {
- if ((new String(var1)).toUpperCase().equals("DEFAULT")) {
- this.m_treatBlankAs = 0;
- } else if ((new String(var1)).toUpperCase().equals("NULL")) {
- this.m_treatBlankAs = 1;
- } else {
- if ((new String(var1)).toUpperCase().equals("BLANK")) {
- this.m_treatBlankAs = 2;
- }
-
- }
- }
-
- void raiseException(String var1) {
- System.out.println(var1);
- }
- }
-